#include "cpu/exec/template-start.h"
#define instr call

make_helper(concat(call_i_, SUFFIX)) {
    int len = concat(decode_i_, SUFFIX)(eip + 1);
    uint32_t ret = cpu.eip + len + 1;   // address of next instruction (fall-through)
    reg_l(R_ESP) -= DATA_BYTE;
    MEM_W(reg_l(R_ESP), ret);

    int32_t offset = (DATA_BYTE == 1) ? (int8_t)op_src->val : (DATA_TYPE_S)op_src->val;
    uint32_t target = ret + offset;

    cpu.eip = target - (len + 1); 
    print_asm("call: 0x%x", target);
    return len + 1;
}

make_helper(concat(call_rm_, SUFFIX)) {
    int len = concat(decode_rm_, SUFFIX)(eip + 1);
    uint32_t ret = cpu.eip + len + 1;
    reg_l(R_ESP) -= DATA_BYTE;
    MEM_W(reg_l(R_ESP), ret);

    uint32_t target = op_src->val; 
    cpu.eip = target - (len + 1);
    print_asm("call: %s", op_src->str);
    return len + 1;
}

#include "cpu/exec/template-end.h"
